import base64, json, pickle

def get_license(src_fileName, dest_fileName):
    src_contents = ''
    try:
        with open(src_fileName, encoding='utf-8') as f:
            src_contents = f.read()
        src_contents = json.loads(src_contents)
        if len(src_contents) < 2:
            print(f'原始授权文件异常, path={src_fileName}')
            return
        src_contents = bytes('{}'.format(src_contents), 'utf-8')
        dest_contents = base64.encodebytes(src_contents)
        dest_str = pickle.dumps(dest_contents).decode('latin1')
        with open(dest_fileName, 'w', encoding='utf-8') as f:
            f.write(dest_str)
        print(f'已生成授权文件{dest_fileName}')
    except FileNotFoundError:
        msg = f'授权原始文件{src_fileName}不存在...'
        print('synlog=', msg)
    except PermissionError:
        msg = f'授权原始文件{src_fileName}存在但没有权限访问...'
        print('synlog=', msg)
    except Exception as e:
        msg = f'异常{str(e)}...'
        print('synlog=', msg)

if __name__ == '__main__':
    get_license('./diningpos_license', './diningpos_licensees')